/*
* Copyright (c) GBA-NCTI-ISDC. 2022-2024.
*
* openGauss embedded is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
*
* http://license.coscl.org.cn/MulanPSL2
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FITFOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* -------------------------------------------------------------------------
*
* math_op_type.h
*
* IDENTIFICATION
* openGauss-embedded/src/compute/sql/include/common/math_op_type.h
*
* -------------------------------------------------------------------------
*/
#pragma once

#include <fmt/core.h>
#include <fmt/format.h>

#include <string>

enum class MathOpType : uint8_t { Invalid, Plus, Minus, Multiply, Divide, Mod };

MathOpType ToMathOpType(const std::string& op_name);

bool IsMathOp(const std::string& op_name);

template <>
struct fmt::formatter<MathOpType> : formatter<std::string_view> {
    template <typename FormatContext>
    auto format(MathOpType c, FormatContext& ctx) const {
        std::string_view name;
        switch (c) {
            case MathOpType::Plus: {
                name = "+";
                break;
            }
            case MathOpType::Minus: {
                name = "-";
                break;
            }
            case MathOpType::Multiply: {
                name = "*";
                break;
            }
            case MathOpType::Divide: {
                name = "/";
                break;
            }
            case MathOpType::Mod: {
                name = "%";
                break;
            }
            default: {
                name = "invalid";
                break;
            }
        }
        return formatter<std::string_view>::format(name, ctx);
    }
};